/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sadfinanceiro;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

/**
 *
 * @author Felipe
 */
@Entity
@Table(name = "INDICES", catalog = "", schema = "APP")
@NamedQueries({@NamedQuery(name = "Indices.findAll", query = "SELECT i FROM Indices i"), @NamedQuery(name = "Indices.findByPercentual", query = "SELECT i FROM Indices i WHERE i.percentual = :percentual"), @NamedQuery(name = "Indices.findByTipo", query = "SELECT i FROM Indices i WHERE i.tipo = :tipo"), @NamedQuery(name = "Indices.findByMesano", query = "SELECT i FROM Indices i WHERE i.mesano = :mesano"), @NamedQuery(name = "Indices.findByIdIndice", query = "SELECT i FROM Indices i WHERE i.idIndice = :idIndice")})
public class Indices implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Column(name = "PERCENTUAL")
    private Double percentual;
    @Column(name = "TIPO")
    private Short tipo;
    @Column(name = "MESANO")
    @Temporal(TemporalType.DATE)
    private Date mesano;
    @Id
    @Basic(optional = false)
    @Column(name = "ID_INDICE")
    private Short idIndice;

    public Indices() {
    }

    public Indices(Short idIndice) {
        this.idIndice = idIndice;
    }

    public String getPercentualAsString() {
        return new DecimalFormat("0.00").format(percentual);
    }

    public Double getPercentual() {
        return percentual;
    }

    public void setPercentual(Double percentual) {
        Double oldPercentual = this.percentual;
        this.percentual = percentual;
        changeSupport.firePropertyChange("percentual", oldPercentual, percentual);
    }

    public Short getTipo() {
        return tipo;
    }

    public void setTipo(Short tipo) {
        Short oldTipo = this.tipo;
        this.tipo = tipo;
        changeSupport.firePropertyChange("tipo", oldTipo, tipo);
    }

    public Date getMesano() {
        return mesano;
    }

    public String getMesAnoAsString() {
        SimpleDateFormat format = new SimpleDateFormat("MM/yyyy");
        return format.format(mesano);
    }

    public void setMesano(Date mesano) {
        Date oldMesano = this.mesano;
        this.mesano = mesano;
        changeSupport.firePropertyChange("mesano", oldMesano, mesano);
    }

    public Short getIdIndice() {
        return idIndice;
    }

    public void setIdIndice(Short idIndice) {
        Short oldIdIndice = this.idIndice;
        this.idIndice = idIndice;
        changeSupport.firePropertyChange("idIndice", oldIdIndice, idIndice);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idIndice != null ? idIndice.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Indices)) {
            return false;
        }
        Indices other = (Indices) object;
        if ((this.idIndice == null && other.idIndice != null) || (this.idIndice != null && !this.idIndice.equals(other.idIndice))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "sadfinanceiro.Indices[idIndice=" + idIndice + "]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }

}
